package com.fau.cm.entity;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

import org.apache.commons.lang3.time.DateFormatUtils;
import org.hibernate.annotations.GenericGenerator;
import org.json.simple.JSONAware;
import org.json.simple.JSONObject;

/**
 * @desc 电话黑名单表
 * @author liy
 * @datetime 2014年12月11日,下午5:33:59
 */
@Entity
@Table(name = "medical_call_blacklist")
public class MedicalCallBlacklist implements Serializable, JSONAware {

	private static final long serialVersionUID = -7531719585653866081L;
	
	private String id;
	private String phoneNum;				// 电话号码
	private MedicalCallCustomer customer;	// 客户Id
	private String eid;						// 企业ID
	
	private Date createTime = new Date();
	private Date updateTime = new Date();
	
	private String cid;
	private String uname;

	@Id
	@GenericGenerator(name = "generator", strategy = "uuid.hex")
	@GeneratedValue(generator = "generator")
	@Column(name = "id", length = 32)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name = "phone_num", length = 15)
	public String getPhoneNum() {
		return phoneNum;
	}

	public void setPhoneNum(String phoneNum) {
		this.phoneNum = phoneNum;
	}

	@ManyToOne
	@JoinColumn(name="cid")
	public MedicalCallCustomer getCustomer() {
		return customer;
	}

	public void setCustomer(MedicalCallCustomer customer) {
		this.customer = customer;
	}

	@Transient
	public String getCid() {
		return cid;
	}

	public void setCid(String cid) {
		this.cid = cid;
	}

	@Column(name = "create_time")
	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	@Column(name = "update_time")
	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	@Column(name = "eid", length = 32)
	public String getEid() {
		return eid;
	}

	public void setEid(String eid) {
		this.eid = eid;
	}

	@Transient
	public String getUname() {
		return uname;
	}

	public void setUname(String uname) {
		this.uname = uname;
	}

	@SuppressWarnings("unchecked")
	@Override
	public String toJSONString() {
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("id", id);
		jsonObject.put("phoneNum", phoneNum);
		if(null != customer) {
			jsonObject.put("cid", customer.getId());
			jsonObject.put("customerName", customer.getName());
		}
		jsonObject.put("eid", eid);
		jsonObject.put("createTime", DateFormatUtils.format(createTime, "yyyy-MM-dd HH:mm:ss"));
		jsonObject.put("updateTime", DateFormatUtils.format(updateTime, "yyyy-MM-dd HH:mm:ss"));
		return jsonObject.toString();
	}

}
